package com.fafian.publish.json;

import java.util.Map;

import com.fafian.publish.json.exceptions.JSONWorkerGeneratorException;

public class JSONWorkerGenerator {
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static JSONAbstractSynchronousWorker 
		getWorker(String uri, String className, Map<String, String> parameters) throws JSONWorkerGeneratorException {
		try{
			JSONAbstractSynchronousWorker toReturn = (JSONAbstractSynchronousWorker) Class.
					forName(className).newInstance();
			toReturn.setUri(uri);
			toReturn.init(parameters);
			return toReturn;
		} catch (Exception e){
			throw new JSONWorkerGeneratorException(e); 

		}
	}
	
	@SuppressWarnings("rawtypes")
	public static JSONAbstractSynchronousWorker 
		getWorker(JSONWorkerDescription description) throws JSONWorkerGeneratorException{
		return getWorker(description.getUri(), description.getClassName(), description.getParameters());
	}
	
}
